package com.day15;

/**
 * 练习:创建两个分线程，其中一个线程遍历100以内的偶数，另一个遍历100以内的奇数
 */
public class ThreadDemo {
    public static void main(String[] args) {
//        new Mythread().start();
////        new Mthread2().start();

        //创建Thread类的匿名子类的方式()
        new Thread(){
            public void run(){
                for (int i = 0; i < 100; i++) {
                    if (i % 2 == 0) {
                        System.out.println(i);
                    }
                }
            }
        }.start();

        new Thread(){
            public void run(){
                for (int i = 0; i < 100; i++) {
                    if (i % 2 != 0) {
                        System.out.println(i);
                    }
                }
            }
        }.start();
    }

}


class Mythread extends Thread {
    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            if (i % 2 == 0) {
                System.out.println(i);
            }
        }
    }
}

class Mthread2 extends Thread {
    @Override
    public void run() {
        for (int i = 0; i <= 100; i++) {
            if(i % 2 != 0){
                System.out.println(i);
            }
        }
    }
}
